package com.bobi.tfca.web.security;

import cn.hutool.core.lang.Pair;
import lombok.Getter;
import lombok.Setter;
import org.springframework.security.authentication.AbstractAuthenticationToken;

/**
 * 认证令牌，token
 */
public class JwtToken extends AbstractAuthenticationToken {

    /**
     * 用户信息
     * Pair<userId, username>
     */
    private Pair<Integer, String> principal;

    /**
     * jwt token
     */
    private final String credentials;


    public JwtToken(String credentials) {
        super(null);
        this.credentials = credentials;
        super.setAuthenticated(false);
    }

    public JwtToken(Integer userId, String username, String credentials) {
        super(null);
        this.principal = new Pair<>(userId, username);
        this.credentials = credentials;
        super.setAuthenticated(true);
    }

    @Override
    public Object getCredentials() {
        return credentials;
    }

    @Override
    public Pair<Integer, String> getPrincipal() {
        return principal;
    }

}
